package cn.xuan.zp.web.unauthorized;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.xuan.zp.web.authenticate.Authen;

/***
 * 没有权限页面信息跳转处理
 * @author XuanZP
 *
 */
@Controller
@RequestMapping("/unauthorized")
public class UnauthorizedConbtroller {
    private static final Logger LOGGER = LoggerFactory.getLogger(UnauthorizedConbtroller.class);
	
	@RequestMapping("/to")
	public ModelAndView unauthorized(HttpServletRequest request) {
		ModelAndView mv = new ModelAndView();
		LOGGER.info("isAjaxRequest"+isAjaxRequest(request));
		mv.addObject("isAjaxRequest", isAjaxRequest(request));
		mv.setViewName("test");
		return mv;
	}
	
	
	private boolean isAjaxRequest(HttpServletRequest request){
        String header = request.getHeader("X-Requested-With");
        boolean isAjax = "XMLHttpRequest".equals(header) ? true:false;
        return isAjax;
    }

}
